//
//  ViewController.m
//  30101
//
//  Created by student on 16/3/17.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UILabel *label3;
@property (weak, nonatomic) IBOutlet UILabel *label4;
@property(strong,nonatomic) UIView *moveview;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.moveview=[[UIView alloc]initWithFrame:CGRectMake(200, 200, 50, 50)];
    self.moveview.backgroundColor=[UIColor blackColor];
    [self.view addSubview:self.moveview];
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveV:)];
    [self.moveview addGestureRecognizer:pan];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)moveV:(UIPanGestureRecognizer *)g
{
    // 偏移多少
    CGPoint tran = [g translationInView:self.moveview];
    
    // 加上偏移
    self.moveview.center = CGPointMake(self.moveview.center.x+tran.x, self.moveview.center.y+tran.y);
    
    // 重置偏移量
    [g setTranslation:CGPointZero inView:self.moveview];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    NSLog(@"%s",__func__);
    self.label1.text=@"触摸开始";
    self.label2.text=[NSString stringWithFormat:@"数量%lu",(unsigned long)touches.count];
    UITouch *touch=touches.anyObject;
    CGPoint p=[touch locationInView:self.view];
    self.label3.text=[NSString stringWithFormat:@"坐标%@",NSStringFromCGPoint(p)];
    self.label4.text=[NSString stringWithFormat:@"连击%lu",(unsigned long)touch.tapCount];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    NSLog(@"%s",__func__);
    self.label1.text=@"触摸移动";
    UITouch *touch = touches.anyObject;
//    CGPoint  p = [touch locationInView:self.view];
//    CGPoint mp=self.moveview.center;

}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    NSLog(@"%s",__func__);
    self.label1.text=@"触摸结束";
}
- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    NSLog(@"%s",__func__);
}

@end
